package org.java8newfeature.stream;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public class Section13 {

    public static void main(String[] args) {
   /*     Arrays.asList("abc","def").forEach(System.out::println);
        List list = Arrays.asList("abc","def");

        Consumer listc  =new Consumer<String>(){

            @Override
            public void accept(String s) {
                System.out.println(s.toUpperCase());
            }
        };
        list.forEach(listc);*/


  /*      Map<String, Integer> codes = new HashMap<>();
        codes.put("United States", 1);
        codes.put("Germany", 49);
        codes.put("France", 33);
        codes.put("China", 86);
        codes.put("Pakistan", 92);

       BiConsumer biConsumer = (s,i)-> {
           System.out.println(s);
           System.out.println(i);
       };

        codes.forEach(biConsumer);

        codes.forEach((s,i)->{
            System.out.println("key="+s+"  values = "+i);
        });*/

     /*   List<Integer> codes = Arrays.asList(1, 2, 3, 4, 5, 6);
        Consumer<Integer> consumer = System.out::println;
        codes.stream()
                .filter(integer ->  integer%2==0)
                .forEach(consumer);*/

        HashMap<String,Integer> map = new HashMap<>();
        map.put("A",1);
        map.put("B",2);
        map.put("C",3);

        Consumer<Map.Entry<String,Integer>> action = System.out::println;
        //使用consumer是因为将map转成map.set,也就是set集合而不是map了
        map.entrySet().forEach(action);

        Consumer<String> keys = System.out::println;
        map.keySet().forEach(keys);




    }

}
